var express = require('express');
var router = express.Router();
var userkeys = require('../utils/userkeys');
var Users = require('../../db/UsersIf');
var util = require('util');
var querystring = require('querystring');
var Devices = require('../../db/DevicesIf');



router.post('/', function(req, res, next) {
  if(req.session.user) {
    var postdata = '';
    req.on('data', function(chunk) {
      postdata += chunk;
    });

    req.on('end', function() {
      postdata = querystring.parse(postdata);
      console.log("recv postdata:" + util.inspect(postdata));
      Devices.Insert('myuserkey', 'mydeviceimeishansjlin', 'mydevicetype');

      var json = {errCode: 0, errMsg: ''};
      res.json(json);
    });


  } else {
    var json = {errCode: 10001, errMsg: 'no login'};
    res.json(json);
  }
});


module.exports = router;